package demo2;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Test2 {
    public static void main(String[] args) {
        List<Card> list = buyCards();
        shuffle(list);
        System.out.println(list);

        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();
        List<List<Card>> sum = new ArrayList<>();
        sum.add(hand1);
        sum.add(hand2);
        sum.add(hand3);
        hand(list, sum);
        System.out.println(hand1);
        System.out.println(hand2);
        System.out.println(hand3);
        System.out.println("余剩的牌");
        System.out.println(list);
    }
    public static void hand(List<Card> list , List<List<Card>> sum ){
       for (int i = 0 ; i < 5 ;i++){
           for (int j = 0; j < 3; j++) {
            sum.get(j).add(list.remove(0));
           }
       }

    }

    public static List<Card> buyCards(){
        List<Card> list = new ArrayList<>() ;
        String[] colors  = {"♠" ,"♥" , "♦" , "♣"};
        for (int i = 0; i < colors.length; i++) {
            for (int j = 1; j <= 13; j++) {
                Card card = new Card(colors[i] , j) ;
                list.add(card) ;
            }
        }
       return list ;
    }

    public static void shuffle(List<Card> list){
        Random random = new Random( );
        for (int i = 0; i < list.size(); i++) {
            int ret = random.nextInt(52);
            Card tmp = list.get(ret);
            list.set(ret , list.get(i));
            list.set(i , tmp) ;
        }
    }

}
